home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / devel / vbcc-ppc-src / pasm / ppcasm.h < prev    next >
C/C++ Source or Header  |  1999-01-01  |  24KB  |  658 lines

  1. /* $VER: pasm ppcasm.h V1.2a (16.01.99)
  2.  *
  3.  * This file is part of pasm, a portable PowerPC assembler.
  4.  * Copyright (c) 1997-98  Frank Wille
  5.  *
  6.  * pasm is freeware and part of the portable and retargetable ANSI C
  7.  * compiler vbcc, copyright (c) 1995-98 by Volker Barthelmann.
  8.  * pasm may be freely redistributed as long as no modifications are
  9.  * made and nothing is charged for it. Non-commercial usage is allowed
  10.  * without any restrictions.
  11.  * EVERY PRODUCT OR PROGRAM DERIVED DIRECTLY FROM MY SOURCE MAY NOT BE
  12.  * SOLD COMMERCIALLY WITHOUT PERMISSION FROM THE AUTHOR.
  13.  *
  14.  *
  15.  * v1.2a  (16.01.99) phx
  16.  *        Compiles on SGI Irix 5.3.
  17.  * v1.2   (24.10.98) phx
  18.  *        @sdarx small data support.
  19.  *        An empty section with reloc symbols will no longer be deleted.
  20.  * v1.1d  (27.09.98) phx
  21.  *        Rudimentary PPC4xx support (contributed by Jeff Bevis - jab).
  22.  *        Should compile on a (gasp!) Wintel-box.
  23.  * v1.1c  (22.09.98) phx
  24.  *        Include file name was trashed.
  25.  * v1.1b  (05.07.98) phx
  26.  *        Introduced section flags SF_CHIP and SF_FAST for EHF/ADos. They
  27.  *        are set by the new section attributes "C" and "F".
  28.  * v1.1a  (20.06.98) phx
  29.  *        F_UPDATE. Check rA = rD for update instructions.
  30.  * v1.1   (19.06.98) phx
  31.  *        Multiple small data sections are supported. The new directive
  32.  *        .sdreg should be used to set the base register.
  33.  *        Set R_PPC_TOC16 to R_PPC_SDAREL16.
  34.  * v1.0   (24.05.98) phx
  35.  *        Hopefully all known bugs are fixed now and pasm is usable
  36.  *        on any platform, big endian, little endian and 64-bit.
  37.  *        Fixed some more bugs in the ELF output file generator and
  38.  *        some wrong instructions.
  39.  * v0.9   (03.04.98) phx
  40.  *        ELF bug fix: pasm generated WEAK symbols, instead of GLOBAL ones!
  41.  * v0.8   (14.02.98) phx
  42.  *        Alignment list for each section. This fixes the problems
  43.  *        with optimizations.
  44.  * v0.7   (02.01.98) phx
  45.  *        Define "NetBSDAmiga68k" changed to "NetBSD68k".
  46.  *        Changed ParsedLine (next) and GlobalVars (anotherpass) to
  47.  *        allow more than two assembler passes - as required for
  48.  *        optimizations.
  49.  *        search_instr() is global.
  50.  *        Output format 3 is ADOS (like EHF, but doesn't use HUNK_PPC_CODE).
  51.  * v0.6   (30.10.97) phx
  52.  *        More options. GlobalVars: optinstrmode and supermode.
  53.  * v0.5   (12.10.97) phx
  54.  *        Add userdeflist and usrdefs to GlobalVars for symbol definitions
  55.  *        via the command line.
  56.  *        .set allows symbols to be reused.
  57.  *        Last line of a source text was ignored, if newline is missing.
  58.  * v0.4   (05.07.97) phx
  59.  *        Program returns EXIT_FAILURE if an error occurs.
  60.  *        Base address for absolute code may be set with -B option.
  61.  *        EHF support.
  62.  *        Added R_PPC_TOC16 relocation type.
  63.  *        Option -x automatically declares unknown symbols as
  64.  *        externally defined. New GlobalVars entry: autoextern.
  65.  *        Runs on Linux/DEC-Alpha with 64-bit integers.
  66.  *        Changed program name from "PPCasm" to "pasm". Reason: There
  67.  *        is already a PPCasm for Apple Macintosh.
  68.  * v0.3   (20.04.97) phx
  69.  *        Using correct names for PowerPC relocations.
  70.  *        Added little-endian conversion macros.
  71.  * v0.2   (25.03.97) phx
  72.  *        Writes ELF object for 32-bit PowerPC big-endian. Either absolute
  73.  *        or ELF output format may be selected. ELF is default for all
  74.  *        currently supported platforms. PPCasm supports nine different
  75.  *        relocation types (there are much more...).
  76.  *        Compiles and works also under NetBSD/amiga (68k).
  77.  *        Changed function declaration to 'new style' in all sources
  78.  *        (to avoid problems with '...' for example).
  79.  *        Included NetBSD/amiga as supported architecture.
  80.  * v0.1   (11.03.97) phx
  81.  *        First test version with all PowerPC instructions and most
  82.  *        important directives. Only raw, absolute output.
  83.  * v0.0   (14.02.97) phx
  84.  *        File created. Project started.
  85.  */
  86.  
  87. #include <stdlib.h>
  88. #include <stdio.h>
  89. #include <string.h>
  90. #include <stdarg.h>
  91. #include <ctype.h>
  92.  
  93. /* program's name */
  94. #define PNAME "pasm"
  95.  
  96. /* version/revision */
  97. #define VERSION 1
  98. #define REVISION 2
  99. #define PLEVEL 2
  100.  
  101. /* architecture specific defines */
  102. #if defined (AmigaOS68k)
  103. #define MACHINE "Amiga OS/M68k"
  104. #define BIGENDIAN
  105. #define STDTYPES
  106. #elif defined (AmigaOSPPC)
  107. #define MACHINE "Amiga OS/PowerPC"
  108. #define BIGENDIAN
  109. #define STDTYPES
  110. #elif defined (NetBSD68k)
  111. #define MACHINE "NetBSD/M68k"
  112. #define BIGENDIAN
  113. #define STDTYPES
  114. #elif defined (SolarisSparc)
  115. #define MACHINE "Solaris/Sparc"
  116. #define BIGENDIAN
  117. #define STDTYPES
  118. #elif defined (SunOSSparc)
  119. #define MACHINE "SunOS/Sparc"
  120. #define BIGENDIAN
  121. #define STDTYPES
  122. #elif defined (SCOi386)
  123. #define MACHINE "SCO/i386"
  124. #define LITTLEENDIAN
  125. #define STDTYPES
  126. #elif defined (Linuxi386)
  127. #define MACHINE "Linux/i386"
  128. #define LITTLEENDIAN
  129. #define STDTYPES
  130. #elif defined (LinuxAlpha)
  131. #define MACHINE "Linux/Alpha"
  132. #define LITTLEENDIAN
  133. #define TYPES64BIT
  134. #elif defined (Wintel)  /* jab */
  135. #define MACHINE "Wintel"
  136. #define LITTLEENDIAN
  137. #define STDTYPES
  138. #elif defined (Irix53)
  139. #define MACHINE "Irix5.3/mips"
  140. #define BIGENDIAN
  141. #define STDTYPES
  142. #else
  143. #error Unsupported architecture! Please adapt the source text.
  144. #endif
  145.  
  146. #ifdef STDTYPES
  147. typedef signed char int8;
  148. typedef unsigned char uint8;
  149. typedef signed short int int16;
  150. typedef unsigned short int uint16;
  151. typedef signed long int int32;
  152. typedef unsigned long int uint32;
  153. typedef signed char bool;
  154. #elif defined (TYPES64BIT)
  155. typedef signed char int8;
  156. typedef unsigned char uint8;
  157. typedef signed short int16;
  158. typedef unsigned short uint16;
  159. typedef signed int int32;
  160. typedef unsigned int uint32;
  161. typedef int bool;
  162. #else
  163. #error Unsupported architecture! Please adapt the source text.
  164. #endif
  165.  
  166. /* endian conversion */
  167. #if defined (BIGENDIAN)
  168. #define ECH(x) x
  169. #define ECW(x) x
  170. #define ECVH(x) x
  171. #define ECVW(x) x
  172. #elif defined (LITTLEENDIAN)
  173. #define ECH(x) (((x)&0xff)<<8|((x)&0xff00)>>8)
  174. #define ECW(x) (((x)&0xff)<<24|((x)&0xff00)<<8|((x)&0xff0000)>>8|((x)&0xff000000)>>24)
  175. #define ECVH(x) l2bh(x)
  176. #define ECVW(x) l2bw(x)
  177. #else
  178. #error You have to define either BIGENDIAN or LITTLEENDIAN.
  179. #endif
  180.  
  181.  
  182. /* program constants */
  183.  
  184. #ifndef TRUE
  185. #define TRUE 1
  186. #endif
  187. #ifndef FALSE
  188. #define FALSE 0
  189. #endif
  190. #ifndef NULL
  191. #define NULL 0
  192. #endif
  193.  
  194. #define FNAMEBUFSIZE 1024       /* buffer size for file names */
  195. #define EXPSTACKSIZE 32         /* maximum arguments in an expression */
  196.  
  197.  
  198. /* structures */
  199.  
  200. struct node {
  201.   struct node *next;
  202.   struct node *pred;
  203. };
  204.  
  205. struct list {
  206.   struct node *first;
  207.   struct node *dummy;
  208.   struct node *last;
  209. };
  210.  
  211. struct CPUInstr {
  212.   struct CPUInstr *hash_chain;  /* next instruction in hash chain */
  213.   char *name;                   /* instruction's name */
  214.   uint16 flags;                 /* format flags */
  215.   uint8 type;                   /* instruction format, see defines */
  216.   uint8 opcd;                   /* opcode (bit 0-5) */
  217.   uint8 fieldD;                 /* preset D field (bit 6-10) */
  218.   uint8 fieldA;                 /* preset D field (bit 11-15) */
  219.   uint16 xo;                    /* extended opcode (bit 21-31) */
  220. };
  221. /* CPU instruction formats */
  222. #define T_I 0                   /* Bx */
  223. #define T_B 1                   /* BCx */
  224. #define T_DD 2                  /* LWZ */
  225. #define T_DI 3                  /* ADDI */
  226. #define T_DS 4                  /* LD */
  227. #define T_X 5                   /* AND */
  228. #define T_IMM 6                 /* MTFSFI */
  229. #define T_XLB 7                 /* BCLRx */
  230. #define T_XSPR 8                /* MFSPR */
  231. #define T_XCRM 9                /* MTCRF */
  232. #define T_XFL 10                /* MTFSF */
  233. #define T_XS 11                 /* SRADIx */
  234. #define T_A 12                  /* FMADDx */
  235. #define T_M 13                  /* RLWIMIx */
  236. #define T_MD 14                 /* RLDICx */
  237. #define T_CMP 15                /* CMP */
  238. /* CPU instruction flags */
  239. #define F_SUPP_D 0x01           /* D = 0 */
  240. #define F_SUPP_A 0x02           /* A = 0 */
  241. #define F_SUPP_B 0x04           /* B = 0 */
  242. #define F_SUPP_C 0x08           /* C = 0 */
  243. #define F_CRF_D 0x10            /* D = CR field */
  244. #define F_CRF_S 0x20            /* S = CR field */
  245. #define F_SWAP 0x40             /* S instr.: D = S, A and S are swapped */
  246. #define F_SIGNED 0x80           /* 16 bit signed immediate */
  247. #define F_64BIT 0x100           /* 64 bit instruction */
  248. #define F_SUPER 0x200           /* supervisor-only instruction */
  249. #define F_OPTIONAL 0x400        /* optional instruction */
  250. #define F_UPDATE 0x1000         /* update instruction (lwzu, stwux, etc.) */
  251. #define F_EXTENDED 0x8000       /* extended mnemonic */
  252.  
  253. struct Directive {
  254.   struct Directive *hash_chain; /* next directive in hash chain */
  255.   char *name;                   /* directive's name */
  256.   void (*dfunct)();
  257. };
  258.  
  259. struct Macro {
  260.   struct Macro *hash_chain;     /* next macro in hash chain */
  261.   char *name;                   /* macro's name */
  262.   char *text;                   /* ptr to first macro line */
  263.   unsigned long nlines;         /* number of lines in this macro */
  264. };
  265.  
  266. struct AlignPoint {             /* defines an alignment point (.align) */
  267.   struct AlignPoint *next;
  268.   unsigned long offset;         /* section offset for alignent */
  269.   long val;                     /* alignment value */
  270.   long gap;                     /* current alignment gap */
  271. };
  272.  
  273. struct Section {
  274.   struct node n;
  275.   char *name;                   /* section's name */
  276.   uint8 type;                   /* type: code, data, bss, offsets, ... */
  277.   uint8 flags;
  278.   uint8 protection;             /* readable, writable, executable, ... */
  279.   uint8 alignment;              /* number of bits, which have to be zero */
  280.   unsigned long pc;             /* current program counter (sect. offset) */
  281.   unsigned long size;           /* size of section in bytes */
  282.   void *contents;               /* contents, allocated in pass 2 */
  283.   void *data;
  284.   struct AlignPoint *first_align;    /* pointer to first alignment point */
  285.   struct AlignPoint *current_align;  /* current alignment point */
  286.   struct list reloclist;        /* section offsets to relocate */
  287.   struct list xreflist;         /* external references in this section */
  288.   uint32 index;                 /* e.g. section header index for ELF */
  289. };
  290. /* section types */
  291. #define ST_UNDEFINED 0
  292. #define ST_CODE 1               /* section contains code */
  293. #define ST_DATA 2               /* section contains initialized data */
  294. #define ST_UDATA 3              /* section contains uninitialized data */
  295. #define ST_STRUCT 4             /* offset section (will be discarded) */
  296. /* section flags */
  297. #define SF_DISCARD 1            /* can be discarded (e.g. ST_STRUCT) */
  298. #define SF_UNINITIALIZED 2      /* section has uninitialized contents */
  299. #define SF_HASSYMS 4            /* section has reloc symbols */
  300. #define SF_CHIP 0x40            /* EHF: load section to chip ram */
  301. #define SF_FAST 0x80            /* EHF: load section to fast ram */
  302. /* protection */
  303. #define SP_READ 1
  304. #define SP_WRITE 2
  305. #define SP_EXEC 4
  306. #define SP_SHARE 8
  307.  
  308. struct Symbol {
  309.   struct Symbol *hash_chain;    /* next symbol in hash chain */
  310.   char *name;                   /* symbol's name */
  311.   uint32 value;                 /* absolute value or relocation offset */
  312.   struct Section *relsect;      /* symbol def. relative to this section */
  313.   struct AlignPoint *alignpoint;/* sym. was defined after this aligment */
  314.   uint8 type;                   /* absolute, relocatable or extern */
  315.   uint8 flags;
  316.   uint8 info;                   /* section, function or object */
  317.   uint8 bind;                   /* local or global */
  318.   uint32 size;                  /* object's size in bytes */
  319. };
  320. /* symbol type */
  321. #define SYM_UNDEF 0
  322. #define SYM_ABS 1
  323. #define SYM_RELOC 2
  324. #define SYM_EXTERN 3
  325. /* object type */
  326. #define SYMI_NOTYPE 0
  327. #define SYMI_OBJECT 1
  328. #define SYMI_FUNC 2
  329. #define SYMI_SECTION 3
  330. #define SYMI_FILE 4
  331. /* symbol bind */
  332. #define SYMB_NONE 0
  333. #define SYMB_LOCAL 1
  334. #define SYMB_GLOBAL 2
  335. #define SYMB_WEAK 3
  336.  
  337. struct Reloc {
  338.   struct node n;
  339.   unsigned long offset;         /* section-offset of relocation */
  340.   uint32 addend;                /* add this to relocation value */
  341.   struct Section *relocsect;    /* base addr of this sect. has to be added */
  342.   uint8 type;
  343. };
  344. /* reloc types (identical with the reloc types used for ELF) */
  345. #define R_NONE 0
  346. #define R_PPC_ADDR32 1          /* 32-bit relocation */
  347. #define R_PPC_ADDR24 2          /* 26-bit relocation for B-instruction */
  348. #define R_PPC_ADDR16 3          /* 16-bit relocation */
  349. #define R_PPC_ADDR16_LO 4       /* relocation of the lower half-word */
  350. #define R_PPC_ADDR16_HI 5       /* relocation of the higher half-word */
  351. #define R_PPC_ADDR16_HA 6       /* higher half-word reloc. for ADDI */
  352. #define R_PPC_ADDR14 7          /* BC-instruction, 16-bit absolute */
  353. #define R_PPC_ADDR14_BRTAKEN 8
  354. #define R_PPC_ADDR14_BRNTAKEN 9
  355. #define R_PPC_REL24 10          /* relative 26-bit (PowerPC B-instruction) */
  356. #define R_PPC_REL14 11          /* BC-instruction, 16-bit relative */
  357. #define R_PPC_REL14_BRTAKEN 12
  358. #define R_PPC_REL14_BRNTAKEN 13
  359. #define R_PPC_GOT16 14
  360. #define R_PPC_GOT16_LO 15
  361. #define R_PPC_GOT16_HI 16
  362. #define R_PPC_GOT16_HA 17
  363. #define R_PPC_PLTREL24 18
  364. #define R_PPC_COPY 19
  365. #define R_PPC_GLOB_DAT 20
  366. #define R_PPC_JMP_SLOT 21
  367. #define R_PPC_RELATIVE 22
  368. #define R_PPC_LOCAL24PC 23
  369. #define R_PPC_UADDR32 24
  370. #define R_PPC_UADDR16 25
  371. #define R_PPC_REL32 26          /* section base offset */
  372. #define R_PPC_PLT32 27
  373. #define R_PPC_PLTREL32 28
  374. #define R_PPC_PLT16_LO 29
  375. #define R_PPC_PLT16_HI 30
  376. #define R_PPC_PLT16_HA 31
  377. #define R_PPC_SDAREL16 32
  378. #define R_PPC_SECTOFF 33
  379. #define R_PPC_SECTOFF_LO 34
  380. #define R_PPC_SECTOFF_HI 35
  381. #define R_PPC_SECTOFF_HA 36
  382. #define R_PPC_TOC16 R_PPC_SDAREL16
  383.  
  384. struct XReference {
  385.   struct node n;
  386.   struct Symbol *xsymbol;       /* external symbol, which is referenced */
  387.   unsigned long offset;
  388.   uint32 addend;
  389.   uint8 type;                   /* relocation type, see struct Reloc */
  390.   uint8 size;                   /* size of reference in bytes (3 = 26bit) */
  391. };
  392.  
  393. struct ParsedLine {
  394.   uint8 type;                   /* opcode type */
  395.   uint8 flags;
  396.   int8 branch_hint;             /* 0=no hint, 1=b. taken(+), -1=not taken(-)*/
  397.   uint8 narg;                   /* value for $NARG, when calling macro */
  398.   char *lineptr;                /* ptr to source text line */
  399.   void *opcode;                 /* ptr to CPUInstr, Directive or SourceText */
  400.   char *operand;                /* ptr to operand-string */
  401.   struct ParsedLine *next;      /* pasm added another opcode here, if != 0 */
  402. };
  403. /* opcode types */
  404. #define OT_IGNORE 0             /* line is empty or commented out */
  405. #define OT_INSTRUCTION 1
  406. #define OT_DIRECTIVE 2
  407. #define OT_MACRO 3
  408. #define OT_SECTION 4
  409. /* flags */
  410. #define PLF_NONEWLINE 1         /* new statement is still part of same line */
  411. #define PLF_ALIGN 2
  412.  
  413. struct SourceText {             /* start address and size of all text files */
  414.   struct node n;
  415.   char *name;                   /* name of source, include file or macro */
  416.   char *text;                   /* source text pointer */
  417.   unsigned long nlines;         /* number of lines in source text */
  418.   struct ParsedLine *plin;      /* ParsedLine structures for nlines */
  419. };
  420.  
  421. #define MAX_MACPARAMS 10        /* macro parameters \0-\9 */
  422. struct MacroParams {
  423.   char *param[MAX_MACPARAMS];   /* parameter strings, which replace \x */
  424.   uint32 call_id;               /* macro call id */
  425.   uint32 narg;                  /* number of arguments */
  426.   char param0[2];               /* parameter 0 contains the branch hint */
  427. };
  428.  
  429. struct SourceThread {           /* main source, includes and macros */
  430.   struct SourceThread *prev;    /* previous source thread */
  431.   struct MacroParams *macro;    /* only assigned in macro mode */
  432.   struct SourceText *csource;   /* ptr to current source text node */
  433.   char *lineptr;                /* source text pointer to current line */
  434.   char *srcptr;                 /* current source text pointer */
  435.   unsigned long line;           /* current line inside this thread */
  436.   struct Macro *macskip;        /* indicates macro skip mode */
  437. };
  438.  
  439. struct Expression {
  440.   uint32 value;
  441.   uint8 type;                   /* same type definitions as used for Symbol */
  442.   uint8 reloctype;              /* see struct Reloc */
  443.   struct Symbol *symbol;        /* reloc or extern symbol, used in exp. */
  444. };
  445.  
  446. struct UserDefine {
  447.   struct node n;
  448.   char *line;                   /* .set <symbol>,<assignment> */
  449. };
  450.  
  451.  
  452. #define DEF_MAXERRORS 5
  453. #define MAX_INCPATHS 8
  454. #define MAX_IFLEVELS 16
  455. #define LINEBUFSIZE 1024
  456. #define STRBUFSIZE 256
  457. /* number of entries in hash tables */
  458. #define SYMHTABSIZE 0x4000      /* symbol hash table */
  459. #define INSTRHTABSIZE 0x1000    /* instruction hash table */
  460. #define DIRHTABSIZE 0x800       /* directive hash table */
  461. #define MACROHTABSIZE 0x800     /* macro hash table */
  462. /* supported output formats */
  463. #define OFMT_ABSOLUTE 0
  464. #define OFMT_ELF 1
  465. #define OFMT_EHF 2
  466. #define OFMT_ADOS 3
  467. #define OFMT_LAST 3
  468. /* optimization flags */
  469. #define OPT_FAR_BRANCH 0x00010000
  470. /* "Bcc label" with destination out of range will be converted into a */
  471. /* "B!cc *+8/B label" combination. */
  472.  
  473. struct GlobalVars {
  474.   char *source_name;            /* source text file name */
  475.   char *dest_name;              /* output file name */
  476.  
  477.   /* options */
  478.   bool dontwarn;                /* suppress warnings */
  479.   bool noregsymbols;            /* don't predefine register symbols etc. */
  480.   bool noextmnemo;              /* no extended mnemonics */
  481.   bool sixtyfourmode;           /* 64-bit mode activated */
  482.   bool optinstrmode;            /* optional instructions */
  483.   bool supermode;               /* supervisor mode instructions */
  484.   bool autoextern;              /* autom. declare undef. sym. as extern */
  485.   uint8 output;                 /* output format */
  486.   uint32 opt;                   /* optimization flags */
  487.   struct list userdeflist;      /* user defines */
  488.   bool usrdefs;
  489.  
  490.   int maxerrors;                /* # of errors to display, before aborting */
  491.   int errcnt;                   /* number of errors displayed */
  492.   int returncode;               /* return code for exit() */
  493.   char *incpaths[MAX_INCPATHS]; /* paths where to search for files */
  494.   char *ident;                  /* unit identification or comment */
  495.   char *file;                   /* source file name for debugging */
  496.   unsigned long absbase;        /* base address for absolute code */
  497.   struct list sourcelist;       /* source text list */
  498.   struct list sectionlist;      /* defined sections */
  499.  
  500.   struct SourceThread *cthread; /* current source thread */
  501.   struct Section *csect;        /* current section */
  502.   struct Symbol *lcsym;         /* location counter symbol '$' */
  503.   struct Symbol *nargsym;       /* symbol for number of arguments '$NARG' */
  504.   struct SourceText *srctxtp;   /* source text pointer for get_source() */
  505.   uint32 macrocnt;              /* incremented on every macro invocation */
  506.   unsigned long absline;        /* absolute line number */
  507.   uint8 pass;                   /* 0 or 1 */
  508.   uint8 iflevel;                /* current level for conditional assembly */
  509.   uint8 ifignore;               /* number of else/endifs to ignore */
  510.   bool ifcond[MAX_IFLEVELS];    /* ifcond[0] is always TRUE */
  511.   bool signedexp;               /* current expression to eval is signed */
  512.   bool alignflag,vc;
  513.   bool anotherpass;             /* true, if another pass is required */
  514.  
  515.   /* TOC */
  516.   int rtoc;                     /* register number for toc-mode */
  517.   struct Section *tocsect;      /* ptr to TOC section, or NULL */
  518.  
  519.   /* hash tables */
  520.   struct Symbol **symbols;      /* symbol hash table */
  521.   struct CPUInstr **instr;      /* instruction hash table */
  522.   struct Directive **directives; /* directive hash table */
  523.   struct Macro **macros;        /* macro hash table */
  524.  
  525.   /* buffers */
  526.   char linebuf[LINEBUFSIZE];    /* buffer for a whole source text line */
  527.   char strbuf[STRBUFSIZE];      /* string buffer for labels, opcodes, etc. */
  528.   uint8 alignment_bytes[4];     /* four zero bytes */
  529. };
  530.  
  531.  
  532. /* global functions */
  533.  
  534. /* main.c */
  535. #ifndef MAIN_C
  536. extern struct GlobalVars gvars;
  537. extern void cleanup(struct GlobalVars *);
  538. #endif
  539.  
  540. /* version.c */
  541. #ifndef VERSION_C
  542. extern void show_version(void);
  543. extern void show_usage(void);
  544. #endif
  545.  
  546. /* pass.c */
  547. #ifndef PASS_C
  548. extern void exec_pass1(struct GlobalVars *);
  549. extern void pass1(struct GlobalVars *,struct SourceText *,
  550.                   struct MacroParams *,struct SourceThread *);
  551. extern struct SourceText *include_source(struct GlobalVars *,char *);
  552. extern void exec_pass2(struct GlobalVars *);
  553. extern void pass2(struct GlobalVars *,struct SourceText *,
  554.                   struct MacroParams *,struct SourceThread *);
  555. extern struct SourceText *get_source(struct GlobalVars *);
  556. #endif
  557.  
  558. /* support.c */
  559. #ifndef SUPPORT_C
  560. extern void *alloc(size_t);
  561. extern void *alloczero(size_t);
  562. extern char *allocstring(char *);
  563. extern void initlist(struct list *);
  564. extern void addtail(struct list *,struct node *);
  565. extern struct node *remhead(struct list *);
  566. extern struct node *remnode(struct node *);
  567. extern char *mapfile(struct GlobalVars *,char *);
  568. extern void checkrange(uint32,int,bool);
  569. extern void lower_case(char *);
  570. extern int strncmpnc(char *,char *,int);
  571. #ifdef LITTLEENDIAN
  572. extern uint16 l2bh(uint16);
  573. extern uint32 l2bw(uint32);
  574. #endif
  575. #endif
  576.  
  577. /* eval.c */
  578. #ifndef EVAL_C
  579. extern char *getsymbol(struct GlobalVars *,char *);
  580. extern char *getarg(struct GlobalVars *,char *);
  581. extern char *skipspaces(char *);
  582. extern char *remquotes(char *);
  583. extern void checkEOL(char *);
  584. extern char *skipexpression(struct GlobalVars *,char *);
  585. extern void read_macro_params(struct GlobalVars *,struct ParsedLine *,
  586.                               struct MacroParams *,char *);
  587. extern char *getexp(struct GlobalVars *,char *,uint32 *,uint8);
  588. extern uint32 makereloc(struct GlobalVars *,struct Expression *);
  589. extern uint32 makexref(struct GlobalVars *,struct Expression *,uint8);
  590. extern char *getintexp(struct GlobalVars *,char *,uint32 *);
  591. extern char *eval_expression(struct GlobalVars *,struct Expression *,char *);
  592. #endif
  593.  
  594. /* tables.c */
  595. #ifndef TABLES_C
  596. extern void init_hashtables(struct GlobalVars *);
  597. extern void add_macro(struct GlobalVars *,struct Macro *);
  598. extern struct Symbol *add_symbol(struct GlobalVars *,char *,uint8,uint32);
  599. extern struct CPUInstr *search_instr(struct GlobalVars *,char *);
  600. extern unsigned long elf_hash(unsigned char *);
  601. extern struct Symbol *search_symbol(struct GlobalVars *,char *);
  602. extern struct Section *search_section(struct GlobalVars *,char *);
  603. extern void search_opcode(struct GlobalVars *,struct ParsedLine *,
  604.                           char *,char *);
  605. #endif
  606.  
  607. /* errors.c */
  608. #ifndef ERRORS_C
  609. extern void error(int,...);
  610. extern void ierror(char *,...);
  611. #endif
  612.  
  613. /* predefs.c */
  614. extern char stdsects[];
  615. extern char stdsets[];
  616. extern char *xmnemos[];
  617.  
  618. /* elfrelocnames.c */
  619. extern char *elfrel_name[];
  620. #define ELFRELNAMMSK 0x3f  /* number of names in elfrel_name[] minus 1 */
  621.  
  622. /* instructions.c */
  623. #ifndef INSTRUCTIONS_C
  624. extern struct CPUInstr instructions[];
  625. extern void instr(struct GlobalVars *,struct ParsedLine *);
  626. extern char *check_comma(char *);
  627. extern void pcadd(struct GlobalVars *,unsigned long);
  628. extern void store_byte(struct GlobalVars *,uint8);
  629. extern void store_half(struct GlobalVars *,uint16);
  630. extern void store_word(struct GlobalVars *,uint32);
  631. extern void store_float(struct GlobalVars *,double);
  632. extern void store_double(struct GlobalVars *,double);
  633. extern void store_space(struct GlobalVars *,unsigned long);
  634. #endif
  635.  
  636. /* directives.c */
  637. #ifndef DIRECTIVES_C
  638. extern struct Directive directives[];
  639. extern void activate_section(struct GlobalVars *,struct Section *);
  640. extern void alignment(struct GlobalVars *,unsigned long);
  641. extern char escchar(char);
  642. #endif
  643.  
  644. /* output_abs.c */
  645. #ifndef OUTPUT_ABS_C
  646. extern void output_absolute(struct GlobalVars *);
  647. #endif
  648.  
  649. /* output_elf.c */
  650. #ifndef OUTPUT_ELF_C
  651. extern void output_elf32msb(struct GlobalVars *);
  652. #endif
  653.  
  654. /* output_ehf.c */
  655. #ifndef OUTPUT_EHF_C
  656. extern void output_ehf(struct GlobalVars *);
  657. #endif
  658.